package com.tianxinweb.entity;

import com.tianxinweb.enums.ResultEnum;

import java.util.HashMap;
import java.util.Map;

/**
 * 状态返回类
 * @author cboy
 * @date 2017年12月4日
 * @version 1.0
 */

public class Result {
	//状态码   200-成功    201-失败
	private Integer code;
	//提示信息
	private String msg;
	
	//用户要返回给浏览器的数据
	private Map<String, Object> extend = new HashMap<>();
	
	public Result(){}

	public Result(Integer code, String msg, Map<String, Object> extend) {
		this.code = code;
		this.msg = msg;
		this.extend = extend;
	}
	public Result(Integer code, String msg) {
		this.code = code;
		this.msg = msg;
	}

	public static Result success(){
		Result result = new Result();
		result.setCode(ResultEnum.SUCCESS.getCode());
		result.setMsg(ResultEnum.SUCCESS.getMsg());
		return result;
	}
	
	public static Result fail(){
		Result result = new Result();
		result.setCode(ResultEnum.FAILE.getCode());
		result.setMsg(ResultEnum.FAILE.getMsg());
		return result;
	}

	public static Result fail(Integer code,String msg){
		Result result = new Result();
		result.setCode(code);
		result.setMsg(msg);
		return result;
	}
	
	public Result add(String key, Object value){
		this.getExtend().put(key, value);
		return this;
	}
	
	public Integer getCode() {
		return code;
	}

	public void setCode(Integer code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public Map<String, Object> getExtend() {
		return extend;
	}

	public void setExtend(Map<String, Object> extend) {
		this.extend = extend;
	}


}

